#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define ll long long
#define int ll
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define popcnt __builtin_popcount
#define rbtree(way) tree<way,null_type,less<way>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
const int maxn=3e3+10,maxm=1e6+10,mod=998244353,inf=INT_MAX;
inline int ksm(int x,int k,int mod=mod){
	int ans=1;
	for(x%=mod;k;k>>=1,x=x*x%mod) if(k&1) ans=ans*x%mod;
	return ans;
}

int n,m,ans;
short sum[2][maxn][maxn],f[maxn],add[maxn][maxn];
short L[maxn][maxn],R[maxn][maxn],U[maxn][maxn],D[maxn][maxn];
char s[maxn][maxn];

void solve(int xL,int xR,int yL,int yR){
	if(xL==xR||yL==yR) return;
	if(yR-yL>xR-xL){
		int mid=yL+yR>>1;
		solve(xL,xR,yL,mid),solve(xL,xR,mid+1,yR);
		rep(i,xL,xR) rep(j,i+1,xR) sum[0][i][j]=sum[1][i][j]=0;
		
		rep(i,xL,xR) f[i]=0;
		rep(i,xL,xR) rep(j,i+1,xR) add[i][j]=0;
		rep(i,xL,xR) rep(j,max(yL,(int)L[i][mid]),mid) ++add[max(xL,(int)U[i][j])][i];
		rep(i,xL,xR) rep(j,i+1,xR){
			f[j]+=add[i][j];
			if(L[i][mid]<=L[j][mid]) sum[0][i][j]+=f[j];
		}
		
		rep(i,xL,xR) f[i]=0;
		rep(i,xL,xR) rep(j,i+1,xR) add[i][j]=0;
		rep(i,xL,xR) rep(j,mid+1,min(yR,(int)R[i][mid+1])) ++add[max(xL,(int)U[i][j])][i];
		rep(i,xL,xR) rep(j,i+1,xR){
			f[j]+=add[i][j];
			if(R[i][mid+1]>=R[j][mid+1]) sum[1][i][j]+=f[j];
		}
		
		rep(i,xL,xR) f[i]=0;
		rep(i,xL,xR) rep(j,xL,i-1) add[i][j]=0;
		rep(i,xL,xR) rep(j,max(yL,(int)L[i][mid]),mid) ++add[min(xR,(int)D[i][j])][i];
		per(i,xR,xL) per(j,i-1,xL){
			f[j]+=add[i][j];
			if(L[i][mid]<L[j][mid]) sum[0][j][i]+=f[j];
		}
		
		rep(i,xL,xR) f[i]=0;
		rep(i,xL,xR) rep(j,xL,i-1) add[i][j]=0;
		rep(i,xL,xR) rep(j,mid+1,min(yR,(int)R[i][mid+1])) ++add[min(xR,(int)D[i][j])][i];
		per(i,xR,xL) per(j,i-1,xL){
			f[j]+=add[i][j];
			if(R[i][mid+1]>R[j][mid+1]) sum[1][j][i]+=f[j];
		}
		
		rep(i,xL,xR) rep(j,i+1,xR) if(s[i][mid]==s[i][mid+1]) ans+=(int)sum[0][i][j]*(int)sum[1][i][j];
	}
	else{
		int mid=xL+xR>>1;
		solve(xL,mid,yL,yR),solve(mid+1,xR,yL,yR);
		rep(i,yL,yR) rep(j,i+1,yR) sum[0][i][j]=sum[1][i][j]=0;
		
		rep(i,yL,yR) f[i]=0;
		rep(i,yL,yR) rep(j,i+1,yR) add[i][j]=0;
		rep(i,yL,yR) rep(j,max(xL,(int)U[mid][i]),mid) ++add[max(yL,(int)L[j][i])][i];
		rep(i,yL,yR) rep(j,i+1,yR){
			f[j]+=add[i][j];
			if(U[mid][i]<=U[mid][j]) sum[0][i][j]+=f[j];
		}
		
		rep(i,yL,yR) f[i]=0;
		rep(i,yL,yR) rep(j,i+1,yR) add[i][j]=0;
		rep(i,yL,yR) rep(j,mid+1,min(xR,(int)D[mid+1][i])) ++add[max(yL,(int)L[j][i])][i];
		rep(i,yL,yR) rep(j,i+1,yR){
			f[j]+=add[i][j];
			if(D[mid+1][i]>=D[mid+1][j]) sum[1][i][j]+=f[j];
		}
		
		rep(i,yL,yR) f[i]=0;
		rep(i,yL,yR) rep(j,yL,i-1) add[i][j]=0;
		rep(i,yL,yR) rep(j,max(xL,(int)U[mid][i]),mid) ++add[min(yR,(int)R[j][i])][i];
		per(i,yR,yL) per(j,i-1,yL){
			f[j]+=add[i][j];
			if(U[mid][i]<U[mid][j]) sum[0][j][i]+=f[j];
		}
		
		rep(i,yL,yR) f[i]=0;
		rep(i,yL,yR) rep(j,yL,i-1) add[i][j]=0;
		rep(i,yL,yR) rep(j,mid+1,min(xR,(int)D[mid+1][i])) ++add[min(yR,(int)R[j][i])][i];
		per(i,yR,yL) per(j,i-1,yL){
			f[j]+=add[i][j];
			if(D[mid+1][i]>D[mid+1][j]) sum[1][j][i]+=f[j];
		}
		
		rep(i,yL,yR) rep(j,i+1,yR) if(s[mid][i]==s[mid+1][i]) ans+=(int)sum[0][i][j]*(int)sum[1][i][j];
	}
}

signed main(){
	freopen("star.in","r",stdin),freopen("star.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	rep(i,1,n) rep(j,1,m) cin>>s[i][j],U[i][j]=D[i][j]=L[i][j]=R[i][j]=1;
	rep(i,1,n) rep(j,1,m){
		if(s[i][j]==s[i-1][j]) U[i][j]=U[i-1][j]+1;
		if(s[i][j]==s[i][j-1]) L[i][j]=L[i][j-1]+1;
	}
	per(i,n,1) per(j,m,1){
		if(s[i][j]==s[i+1][j]) D[i][j]=D[i+1][j]+1;
		if(s[i][j]==s[i][j+1]) R[i][j]=R[i][j+1]+1;
	}
	rep(i,1,n) rep(j,1,m) U[i][j]=i-U[i][j]+1,L[i][j]=j-L[i][j]+1,
		D[i][j]=i+D[i][j]-1,R[i][j]=j+R[i][j]-1;
	solve(1,n,1,m),cout<<ans;
	return 0;
}
